package org.the.gsdo.server;

import java.util.logging.Logger;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

//spring must scan this class (see ApplicationConfiguration :: basePackageClasses
@Component
// aspectj
@Aspect
@Profile("prod")
public class LogAspectProd extends LogAspect {

	private static Logger log = Logger.getLogger(LogAspectProd.class.getName());

	@Around("anyPublicMethod() && @annotation(logAction)")
	public Object logAction(ProceedingJoinPoint pjp, LogAction logAction)
			throws Throwable {
		String actionPerformed = logAction.value();
		long start = System.nanoTime();
		log.info(">>>> entry [" + actionPerformed + "], start(nano) = " + start);
		Object ret = pjp.proceed();
		long end = System.nanoTime();
		long diff = end - start;
		log.info("<<<< exit [" + actionPerformed + "], end(nano) = " + end + ", time(nano) = " + diff);
		return ret;
	}

}
